package org.awa.demo.opencv.gltf.newhandler;

import org.awa.demo.opencv.gltf.handler.*;
import org.locationtech.jts.math.Vector3D;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class NewRectangleAssigner {

    @Autowired
    private NewFloorHandler floorHandler;

    @Autowired
    private NewWallXHandler wallXHandler;

    @Autowired
    private NewWallYHandler wallYHandler;

    @Autowired
    private NewWallHypoHandler wallHypoHandler;

    public INewRectangleHandler getRectangleHandler(List<Vector3D> blenderPointList) {
        if(blenderPointList.size() == 0) {
            return null;
        }
        long countX = blenderPointList.parallelStream().map(point -> {
            return point.getX();
        }).distinct().count();

        long countY = blenderPointList.parallelStream().map(point -> {
            return point.getY();
        }).distinct().count();

        long countZ = blenderPointList.parallelStream().map(point -> {
            return point.getZ();
        }).distinct().count();

        boolean xChanged = countX > 1;
        boolean yChanged = countY > 1;;
        boolean zChanged = countZ > 1;;

        if(xChanged && yChanged && zChanged){
            //斜边
            return wallHypoHandler;
        }else if(!xChanged){
            //X正边
            return wallXHandler;
        }else if(!yChanged){
            //Y正边
            return wallYHandler;
        }else{
            //地面
            return floorHandler;
        }
    }
}
